import router from './index';
import tool from '@/utils/tool';

router.beforeEach(async (to, from, next) => {
  let token = tool.getCookie('X-Token');
  if (token) {
    next();
    if (from.path === '/') {
      if (to.path === '/project') {
        // alert('有的！')
        if (location.href.indexOf("#reloaded") == -1) {
          location.href = location.href + "#reloaded";
          location.reload();
        }
      } else if (to.path === '/') {
        next('/all/general');
      }
    }
  } else {
    window.localStorage.clear();
    localStorage.stop = true;
    window.close()
    let host = process.env.NODE_ENV == 'development' ? process.env.VUE_APP_HOME_URL : process.env.VUE_APP_HOME_URL_PROD;
    window.open(host)
  }
});

router.afterEach(() => {});